﻿using UnityEngine;

namespace ZSW.Framework.Utils
{
    public static class ZSWFUtil_Color
    {
        /// <summary>
        /// 颜色叠加
        /// </summary>
        /// <param name="color"></param>
        /// <param name="r"></param>
        /// <param name="g"></param>
        /// <param name="b"></param>
        /// <param name="a"></param>
        /// <returns></returns>
        public static Color Overlay(Color color, float r, float g, float b, float a = 0)
        {
            color.r += r;
            color.r = Mathf.Clamp(color.r, 0f, 1f);
            color.g += g;
            color.g = Mathf.Clamp(color.g, 0f, 1f);
            color.b += b;
            color.b = Mathf.Clamp(color.b, 0f, 1f);
            color.a += a;
            color.a = Mathf.Clamp(color.a, 0f, 1f);
            return color;
        }

        /// <summary>
        /// 创建指定长度颜色数组
        /// </summary>
        /// <param name="count"></param>
        /// <param name="color"></param>
        /// <returns></returns>
        public static Color[] Shape(int count, Color color)
        {
            Color[] colors = new Color[count];
            for (int i = 0; i < colors.Length; i++)
            {
                colors[i] = color;
            }
            return colors;
        }

        public static Color SetAlpha(Color color, float alpha)
        {
            color.a = alpha;
            return color;
        }
    }
}